package com.zy.web.controller.business;

import com.zy.business.domain.vo.VisitorDto;
import com.zy.business.domain.TbVisitorInfo;
import com.zy.business.domain.TbVisitorRecord;
import com.zy.business.service.VisitorInfoService;
import com.zy.business.service.VisitorRecordService;
import com.zy.common.core.controller.BaseController;
import com.zy.common.core.domain.AjaxResult;
import com.zy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @description:访客控制器
 * @author: whf
 * @create: 2022-03-17 17:21
 **/
@Api(tags = "访客管理接口")
@RestController
@RequestMapping("/visitor")
public class VisitorInfoController extends BaseController {

    @Autowired
    private VisitorInfoService visitorInfoService;

    @Autowired
    private VisitorRecordService visitorRecordService;

    /*@ApiOperation("获取访客列表")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(name = "type") Integer type) {
        startPage();
        List<TbVisitorInfo> visitorInfoList = visitorInfoService.queryList(type);
        return getDataTable(visitorInfoList);
    }*/

    @ApiOperation("获取openId")
    @GetMapping("/getOpenId")
    public AjaxResult getOpenId(@RequestParam(name="code") String code){
        return visitorInfoService.getOpenId(code);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo(@RequestParam(name="openId") String openId){
        return visitorInfoService.getUserInfo(openId);
    }

    /*@ApiOperation("获取拜访对象列表")
    @GetMapping("/getVisitObject")
    public AjaxResult getVisitObject(){
        return visitorInfoService.getVisitObject();
    }*/

    @ApiOperation("预约")
    @PostMapping("/reserve")
    public AjaxResult reserve(@RequestBody TbVisitorRecord visitorRecord){
        return visitorInfoService.saveRecord(visitorRecord);
    }

    /*@ApiOperation(value = "作废")
    @PostMapping("/invalid")
    public AjaxResult invalid(@RequestParam(name="recordId") Long recordId){
        TbVisitorRecord record = visitorRecordService.getById(recordId);
        record.setIsInvalid(1);
        record.setUpdateTime(new Date());
        visitorRecordService.updateById(record);
        return AjaxResult.success();
    }*/

    /*@ApiOperation(value = "黑名单(type:1加入,0移除)")
    @PostMapping("/addBlack")
    @Transactional
    public AjaxResult addBlack(@RequestBody TbVisitorInfo visitor){
        TbVisitorInfo visitorInfo = visitorInfoService.getById(visitor.getVisitorId());
        visitorInfo.setIsBlack(visitor.getType());
        if(visitor.getType()==1){
            visitorInfo.setJoinReason(visitor.getJoinReason());
        }
        visitorInfo.setUpdateTime(new Date());
        visitorInfoService.updateById(visitorInfo);
        return AjaxResult.success();
    }*/

    @ApiOperation(value = "获取拜访记录列表")
    @GetMapping("/record/list")
    public TableDataInfo recordList(VisitorDto dto) {
        startPage();
        List<TbVisitorRecord> recordList = visitorRecordService.queryList(dto);
        return getDataTable(recordList);
    }
    @ApiOperation("根据recordId获取拜访记录")
    @GetMapping("/getRecord")
    public AjaxResult getRecord(@RequestParam Long recordId){
        TbVisitorRecord record = visitorRecordService.getInfo(recordId);
        return AjaxResult.success(record);
    }

    @ApiOperation(value = "获取通知人")
    @GetMapping("/getRemindUser")
    public AjaxResult getRemindUser(){
        return visitorRecordService.getRemindUser();
    }

    @ApiOperation(value = "配置通知人")
    @PostMapping("/configUser")
    public AjaxResult configUser(String userIds){
        visitorRecordService.configUser(userIds);
        return AjaxResult.success();
    }

    /*@ApiOperation(value = "审核")
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody TbVisitorRecord visitorRecord, HttpServletRequest request){
        return visitorRecordService.audit(visitorRecord,request);
    }*/

}
